home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / db / esm-3.1 / esm-3 / usr / local / sm / src / serverlib / util / reply.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-05  |  5.5 KB  |  214 lines

  1. /*
  2.  *   $RCSfile: reply.c,v $  
  3.  *   $Revision: 1.1.1.1 $  
  4.  *   $Date: 1996/05/04 21:56:03 $      
  5.  */ 
  6. /**********************************************************************
  7. * EXODUS Database Toolkit Software
  8. * Copyright (c) 1991 Computer Sciences Department, University of
  9. *                    Wisconsin -- Madison
  10. * All Rights Reserved.
  11. *
  12. * Permission to use, copy, modify and distribute this software and its
  13. * documentation is hereby granted, provided that both the copyright
  14. * notice and this permission notice appear in all copies of the
  15. * software, derivative works or modified versions, and any portions
  16. * thereof, and that both notices appear in supporting documentation.
  17. *
  18. * THE COMPUTER SCIENCES DEPARTMENT OF THE UNIVERSITY OF WISCONSIN --
  19. * MADISON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION.  
  20. * THE DEPARTMENT DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES
  21. * WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
  22. *
  23. * The EXODUS Project Group requests users of this software to return 
  24. * any improvements or extensions that they make to:
  25. *
  26. *   EXODUS Project Group 
  27. *     c/o David J. DeWitt and Michael J. Carey
  28. *   Computer Sciences Department
  29. *   University of Wisconsin -- Madison
  30. *   Madison, WI 53706
  31. *
  32. *     or exodus@cs.wisc.edu
  33. *
  34. * In addition, the EXODUS Project Group requests that users grant the 
  35. * Computer Sciences Department rights to redistribute these changes.
  36. **********************************************************************/
  37.  
  38. #include "sysdefs.h"
  39. #include "ess.h"
  40. #include "checking.h"
  41. #include "trace.h"
  42. #include "error.h"
  43. #include "io.h"
  44. #include "list.h"
  45. #include "tid.h"
  46. #include "lock.h"
  47. #include "object.h"
  48. #include "msgdefs.h"
  49. #include "thread.h"
  50. #include "semaphore.h"
  51. #include "link.h"
  52. #include "lsn.h"
  53. #include "latch.h"
  54. #include "bf.h"
  55. #include "volume.h"
  56. #include "trans.h"
  57. #include "bitvec.h"
  58. #include "openlog.h"
  59. #include "logrecs.h"
  60. #include "msgvector.h"
  61. #include "msg_funcs.h"
  62. #include "thread_funcs.h"
  63. #include "thread_globals.h"
  64. #include "msg_globals.h"
  65. #include "log_globals.h"
  66. #include "server_util_funcs.h"
  67.  
  68.  
  69.  
  70.  int
  71. reply (
  72.  
  73.     int                    error,
  74.     int                    code,
  75.     int                    vecCount,
  76.     BOOL                taskDie 
  77. )
  78. {
  79.     /*
  80.      *    NOTE: this function builds the reply on the original message.  This
  81.      *          is required so that routines like cl_ReadPage can fill
  82.      *          in information for the reply into the message body.
  83.      *            It is assumed that parts of the original 
  84.      *          message.header are intact, in particular, replyRequested.
  85.      *  There are 2 exceptions: esmBADMESSAGEMAGIC and esmPROTOCOLVERSION.
  86.      *  In these 2 cases, we build a "legit" message from scratch (even though
  87.      *  the client might not understand it!),
  88.      *  after which we close the link.
  89.      */
  90.  
  91.     register TCB        *tcb;
  92.  
  93.  
  94.     TRPRINT(TR_MSG, TR_LEVEL_1, 
  95.             ("thread:%d replying on link:%d code:%d vecCount:%d",
  96.             Active->id, Active->linkId, code, vecCount));
  97.  
  98.     /*
  99.      *    get a register pointer to this thread
  100.      */
  101.     tcb = Active;
  102.  
  103.     if(error == esmNOERROR) {
  104.         /* the client ignores the errno part if it's not a failure */
  105.         code = esmNOERROR;
  106.     } else {
  107.         SM_ASSERT(LEVEL_3, ((error == esmFAILURE)&&(code != esmNOERROR)));
  108.     }
  109.  
  110.     if(code == esmBADMESSAGEMAGIC || code == esmPROTOCOLVERSION) {
  111.         tcb->message.header.replyRequested = TRUE;    
  112.         tcb->message.header.version = MESSAGE_VERSION;    
  113.         tcb->message.header.type = ERROR_REPLY;
  114.     }
  115.  
  116.     if(tcb->message.header.replyRequested == TRUE) {
  117.         {    /* message statistics */     
  118.             int                    messageType;
  119.             messageType = tcb->message.header.type;
  120.             SM_ASSERT(LEVEL_1, ((messageType > 0) && 
  121.                 (messageType <= MAX_MSG_NUMBER)));
  122.             /* no-reply-requested case is counted on INCOMING messages! */
  123.             if(error == esmNOERROR)
  124.                 MsgStats.replied_ok[messageType] ++;
  125.             else
  126.                 MsgStats.replied_in_error[messageType] ++;
  127.         }
  128.             
  129.  
  130. #if TRACING IS_ENABLED
  131.         {
  132.             register int i;
  133.  
  134.             for (i = 0; i < vecCount; i++)    {
  135.                 TRPRINT(TR_MSG, TR_LEVEL_2, 
  136.                     ("vector:%d count:%d", i, tcb->iovec[i].iov_len));
  137.             }
  138.         }
  139. #endif
  140.  
  141.         /*
  142.          *    fill in the errno and the current end of the log
  143.          */
  144.         tcb->message.header.params.out.errno = code;
  145.         tcb->message.header.params.out.endOfLog = OpenLog.nextValidLSN;
  146.         tcb->message.header.params.out.linkTransError = Links[tcb->linkId].linkTransError;    
  147.  
  148.         if(error == esmNOERROR) {
  149.             SM_ASSERT(LEVEL_1, 
  150.             (LOG_PAGE_OFFSET(OpenLog.nextValidLSN.offset, (&OpenLog))!=0));
  151.         }
  152.                 
  153.         TRPRINT(TR_MSG, TR_LEVEL_2, ("first length:%d", tcb->iovec[0].iov_len));
  154.  
  155.         SM_ASSERT(LEVEL_3, vecCount <= MAX_IOVEC);
  156.         if (writev(tcb->linkId, (struct iovec *) tcb->iovec, vecCount) < 0)    {
  157.  
  158.             if ( (errno == EBADF) || (errno == EPIPE) )    {
  159.  
  160.                 TRPRINT(TR_MSG, TR_LEVEL_2, ("bad socket:%d", tcb->linkId));
  161.  
  162.                 /*
  163.                  *     clear the link if it hasn't already been cleared 
  164.                  */
  165.                 if( Links[tcb->linkId].linkClass == CL_CLIENT) {
  166.                     SM_ERROR(TYPE_LOG, errno);
  167.                     freeClientLink( &(Links[tcb->linkId]) );
  168.                 }
  169.  
  170.                 /* check to see if this is a transaction thread */
  171.                 transThreadDeath(tcb);
  172.  
  173.                 /*
  174.                  *    check to see if the task should die
  175.                  */
  176.                 if (taskDie)    {
  177.  
  178.                     threadRestart();
  179.  
  180.                 } else {
  181.  
  182.                     return(esmFAILURE);
  183.                 }
  184.  
  185.             } else { /* errno neither EBADF or EPIPE */
  186.  
  187.                 SM_ERROR(TYPE_FATAL, errno);
  188.             }
  189.         } /* end of writev */
  190.         {
  191.             register int i, totalBytes;
  192.  
  193.             for (totalBytes = 0, i = 0; i < vecCount; i++)    {
  194.                 totalBytes  += tcb->iovec[i].iov_len;
  195.             }
  196.             incPages(totalBytes, SENT, TRUE);
  197.         }
  198.     } /* end of replyRequested */ 
  199.  
  200.     /* check to see if this is a transaction thread */
  201.     transThreadDeath(tcb);
  202.  
  203.     /*
  204.      *    restart this thread
  205.      */
  206.     if (taskDie)    {
  207.  
  208.         TRPRINT(TR_MSG, TR_LEVEL_2, ("task restarting"));
  209.         threadRestart();
  210.  
  211.     } 
  212.     return esmNOERROR;
  213. }
  214.